var twoSum = function(nums, target) {
    // let hash = {};
    let hash = new Map();
    for (let i = 0; i < nums.length; i++) {
        if (hash.has(target - nums[i])) {
            return [i, hash.get(target - nums[i])];
        }
        hash.set(nums[i], i);
    }
    return [];
}

const arr = [1, 2, 3, 4, 5];
console.log(twoSum(arr, 6));